<template>
    <div>
        <van-nav-bar title="注册" left-text="返回" left-arrow @click-left="router.go(-1)" />

        <van-form @submit="onSubmit">
            <van-cell-group inset>
                <van-field v-model="username" name="username" label="账号" placeholder="请输入账号(必填)"
                    :rules="[{ pattern: pattern, required: true, message: '请填写用户名' }]" />
                <van-field v-model="password" type="password" name="password" label="密码" placeholder="请输入密码(必填)"
                    :rules="[{ pattern: pattern1, required: true, message: '请填写密码' }]" />
                <van-field v-model="password" type="password" name="password" label="密码" placeholder="请输入确认密码(必填)"
                    :rules="[{ required: true, message: '请填写密码' }]" />
                <van-field name="姓名" label="姓名" placeholder="请输入姓名(必填)" />
                <van-field label="邮件" placeholder="请输入邮箱" />

                <van-field label="留言" placeholder="请输入留言" />
            </van-cell-group>
            <div style="margin: 16px;">
                <van-button block type="primary" native-type="submit">
                    注册
                </van-button>

            </div>
        </van-form>

    </div>
</template>

<script setup>
import { registerApi } from '@/api/api';
import { ref } from 'vue';
const username = ref('');
const password = ref('');
import { showToast } from 'vant';
import { useRoute, useRouter } from 'vue-router'
const router = useRouter()

let pattern = /^\d{6,}$/
let pattern1 = /^\d{9,}$/

const onSubmit = () => {
    registerApi(username.value, password.value).then((res) => {
        console.log(res);
        if (res.data.code == 0) {
            showToast(res.data.msg);
            router.push('/login')
        } else {
            showToast(res.data.msg);
        }
    })
}
</script>

<style lang="scss" scoped>
.van-button {
    background: red;
    border: none;
    color: #fff;
    border-radius: 0.5rem;

}
</style>